package top.as.sean.api.controller.system;

import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import top.as.sean.biz.system.IDept;
import top.as.sean.common.response.Result;
import top.as.sean.dao.dto.system.DeptAdd;
import top.as.sean.dao.dto.system.DeptEdit;
import top.as.sean.dao.dto.system.DeptPage;
import top.as.sean.dao.vo.system.DeptTree;
import top.as.sean.dao.vo.system.DeptTreeVo;

import java.util.List;

/**
 * 部门
 *
 * @author: ArchieSean
 * @create: 2022/11/8
 */
@RestController
@RequestMapping("dept")
@RequiredArgsConstructor
public class DeptController {

    private final IDept iDept;

    /**
     * 查询所有部门信息
     * @return list
     */
    @GetMapping("all")
    public Result<List<DeptTreeVo>> getAll() {
        return Result.success(iDept.getAll());
    }

    /**
     * 查询部门树形结构
     *
     * @param dto 入参
     * @return result
     */
    @GetMapping("tree")
    public Result<List<DeptTree>> getTree(@ModelAttribute DeptPage dto) {
        return Result.success(iDept.getTree(dto));
    }

    /**
     * 新增部门信息
     *
     * @return boolean
     */
    @PostMapping("add")
    public Result<Boolean> addDept(@Validated @RequestBody DeptAdd dto) {
        return Result.success(iDept.addDept(dto));
    }

    /**
     * 编辑部门信息
     *
     * @param dto 编辑部门信息
     * @return boolean
     */
    @PutMapping("edit")
    public Result<Boolean> editDept(@Validated @RequestBody DeptEdit dto) {
        return Result.success(iDept.editDept(dto));
    }

    /**
     * 删除部门信息
     *
     * @param id 部门id
     * @return boolean
     */
    @DeleteMapping("del")
    public Result<Boolean> removeOne(@RequestParam(name = "id") Long id) {
        return Result.success(iDept.removeOne(id));
    }

}
